﻿<?php

	//密码修改

	ob_clean();//清除缓存
	$id=$_GET['id'];//获取地址栏中参数名是id的值
	//$id=empty($_GET['id'])?0:$_GET['id'];
	if(!empty($_POST["password"])){//用来检测是否做了提交操作

		// 设置数据库传输编码 mysqli_query(数据库连接成功的连接对象，数据库操作sql语句)
		mysqli_query($link,'set names utf8');

		//调用封装
		//加密的
	    $password =md5($_POST["password"]);
	  	//调用封装
	  	$where="id=".$id." and `password`='$password'";
	  	$datas=getSelectByOne('admin',$where);
		//判断是否是ajax请求
		if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
			echo empty($datas)?0:1;die;
		}
		if($_POST['newpassword']!=$_POST['password']&&$_POST['newpassword']==$_POST['cpassword']){
			$data['password']=md5($_POST['newpassword']);
			$where="id=".+$id;
			$_rows=edit('admin',$where,$data);
			// echo $_rows;die;
			if ($_rows>0) {
				echo '<script>alert("密码编辑成功");location.href="index.php?c=admin&a=list&admin=1";</script>';
			}else
			{
				echo '<script>alert("密码编辑失败");history.go(-1);</script>';
			}
		}
	}

 	//加载后台公共视图
	include (VIEW_PATH.$admin.'layout.html');
 ?>
